<?php
namespace app\index\controller;

use app\index\model\Roles as RolesModel;
use app\index\model\Cards as CardsModel;

class Roles
{
    public function index()
    {
        /*
        $model = new RolesModel();
        // $result = $model->get(1);
        // $result = $model->hasWhere('cards', ['code' => '1232'])->find();

        $result = $model->get(5);
        // $result->cards()->save(['code' => '1236']);
        $result->cards->code = '1237';
        $result->cards->save();
        dump($result);
        */
        
        // $model = new RolesModel();
        // $result = $model->get(4, 'cards');
        // dump($result);

        /*
        $model = new CardsModel();
        $result = $model->get(4);
        echo $result->roles->name;
        */

        // $model = new RolesModel();
        // $result = $model->get(1);
        // // dump($result->friends);
        // dump($result->friends()->where('money', 60000)->select());

        $model = new RolesModel();
        // $result = $model->has('friends', '>', 2)->select();
        // $result = $model->has('friends', ['money' => 2000])->select();
        $result = $model->hasWhere('friends', ['money' => 20000], 'name')->select();
        dump($result);

        // $model = new RolesModel();
        // $result = $model->find(3);
        // // $result->friends()->save([
        // //     'name' => '索罗',
        // //     'money' => 4000
        // //     ]);
        // $result->friends()->saveAll([
        //     ['name' => '山治', 'money' => 6000],
        //     ['name' => '罗宾', 'money' => 20000]
        //     ]);
        // dump($result);
    }
}